#-------------------------------------------------------------------------------
# Copyright (c) 2006, 2015 THALES GLOBAL SERVICES.
#  All rights reserved. This program and the accompanying materials
#  are made available under the terms of the Eclipse Public License v1.0
#  which accompanies this distribution, and is available at
#  http://www.eclipse.org/legal/epl-v10.html
#    
#  Contributors:
#     Thales - initial API and implementation
#-------------------------------------------------------------------------------
REF : http://www.ibm.com/developerworks/opensource/library/os-eclipse-dynamicemf/

Now we serialize the model instance document: bookStore.xml. The only difference is that this time, the instance document is serialized with an additional attribute: xsi:schemaLocation. The loader will use this attribute to locate the persisted resource, bookStore.ecore, containing the serialized EPackage needed to load the model instance document.

Listing 8. Serialize model instance document with xsi:schemaLocation attribute
                
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(
    "*", new  XMLResourceFactoryImpl());

Resource resource = resourceSet.createResource(URI.createURI("./bookStore.xml"));
resource.getContents().add(bookStoreObject);

/*
* Save the resource using OPTION_SCHEMA_LOCATION save option toproduce 
* xsi:schemaLocation attribute in the document
*/
Map options = new HashMap();
options.put(XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE);
try{
     resource.save(options);
   }catch (IOException e) {
     e.printStackTrace();
   }

The serialized model instance document, bookstore.xml, would appear with the xsi:schemaLocation attribute...


 
